import HTMLParser
import urllib
import re


urlString="http://www.netnod.se/ix/members"
check=False
check2=False
urlText=[]

class ParseIXP(HTMLParser.HTMLParser):
    def handle_starttag(self,tag,attrs):
        global check
        if tag=="td":
            check=True
                    
    def handle_data(self,data):
        global check
        global check2
        if data!='\n' and check==True:
            if(re.search("Sundsvall",data)):
                check2=True
            if(check2 and re.search("^\d\d*$",data)):
                urlText.append(data)
                check=False
                check2=False           
    def unknown_decl(self,data):
        pass
            
lparser=ParseIXP()
lparser.feed(urllib.urlopen(urlString).read())


filePath="ixp_members.txt"
file = open(filePath,"a")
old=""
urlText.sort()
for item in urlText:
    
    if old!=item:
        #print item
        print >> file, "101 %s" % item
        old=item
file.close()